'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	//连接数据库
		const db=uniCloud.database();
	
		var account=event.account;
		var	password=event.password
		if (!account) {
			return{
					code:500,
					msg:"用户名不能为空"
				}
		}
		if (!password) {
			return{
					code:500,
					msg:"密码不能为空"
				}
		}
		 //查找云数据库表，User是表名
			let result=await db.collection('user').where({
				account:account
			}).get();
			console.log(result)
			if(result.affectedDocs==0){
				return{
					code:500,
					msg:"用户不存在"
				}
			}else{
				if(password==result.data[0].password){
					return{
						code:200,
						msg:"登录成功",
						data:result.data[0]
					}
				}else{
					return{
						code:500,
						msg:"密码错误"
					}
				}
				
			}
	//返回数据给客户端
	return event
};
